package com.sheng.leetcode.year2022.month11.day01;

import org.junit.Test;

/**
 * @author liusheng
 * @date 2022/11/01
 *<p>
 * 1662. 检查两个字符串数组是否相等<p>
 *<p>
 * 给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同，返回 true ；否则，返回 false 。<p>
 * 数组表示的字符串 是由数组中的所有元素 按顺序 连接形成的字符串。<p>
 *<p>
 * 示例 1：<p>
 * 输入：word1 = ["ab", "c"], word2 = ["a", "bc"]<p>
 * 输出：true<p>
 * 解释：<p>
 * word1 表示的字符串为 "ab" + "c" -> "abc"<p>
 * word2 表示的字符串为 "a" + "bc" -> "abc"<p>
 * 两个字符串相同，返回 true<p>
 *<p>
 * 示例 2：<p>
 * 输入：word1 = ["a", "cb"], word2 = ["ab", "c"]<p>
 * 输出：false<p>
 *<p>
 * 示例 3：<p>
 * 输入：word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]<p>
 * 输出：true<p>
 *<p>
 * 提示：<p>
 * 1 <= word1.length, word2.length <= 103<p>
 * 1 <= word1[i].length, word2[i].length <= 103<p>
 * 1 <= sum(word1[i].length), sum(word2[i].length) <= 103<p>
 * word1[i] 和 word2[i] 由小写字母组成<p>
 */
public class LeetCode1662 {

    @Test
    public void test01() {
//        String[] word1 = {"ab", "c"}, word2 = {"a", "bc"};
//        String[] word1 = {"a", "cb"}, word2 = {"ab", "c"};
        String[] word1 = {"abc", "d", "defg"}, word2 = {"abcddefg"};
        System.out.println(new Solution().arrayStringsAreEqual(word1, word2));
    }
}
class Solution {
    public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
        StringBuilder str1 = new StringBuilder("");
        StringBuilder str2 = new StringBuilder("");
        for (int i = 0; i < word1.length; i++) {
            str1.append(word1[i]);
        }
        for (int i = 0; i < word2.length; i++) {
            str2.append(word2[i]);
        }
        return str1.toString().equals(str2.toString());
    }
}
